//
//  APIBaseManager+validator.m
//  BaoZhangWang
//
//  Created by 叶越悦 on 2017/7/26.
//  Copyright © 2017年 yyy. All rights reserved.
//

#import "APIBaseManager+validator.h"

@implementation APIBaseManager (validator)

#pragma mark - 参数和返回数据校验器

- (NSError *)base_validateParameterData:(id)params {
    APIBaseManager <APIManager> *manager = (id <APIManager>) self;
    NSError *error = nil;
    if ([manager respondsToSelector:@selector(validateParameterData:)]) {
        error = [manager validateParameterData:params];
        if (error) {
            return error;
        }
    }
    if (self.validator && [self.validator respondsToSelector:@selector(manager:isCorrectWithParamsData:)]) {
        error = [self.validator manager:self isCorrectWithParamsData:params];
    }
    return error;
}

- (NSError *)base_validateCallBackData:(id)data {
    APIBaseManager <APIManager> *manager = (id <APIManager>) self;
    NSError *error = nil;
    if ([manager respondsToSelector:@selector(validateCallBackData:)]) {
        error = [manager validateCallBackData:data];
        if (error) {
            return error;
        }
    }
    if (self.validator && [self.validator respondsToSelector:@selector(manager:isCorrectWithCallBackData:)]) {
        error = [self.validator manager:self isCorrectWithCallBackData:data];
    }
    return error;
}

@end
